//
//  SyncManager.swift
//  MeenoHybrid
//
//  Created by alyadan on 2016/10/22.
//  Copyright © 2016年 alyadan. All rights reserved.
//

import Foundation
import JavaScriptCore
import YD_Util

@objc public protocol StorageProtocol :JSExport{
    
    func syncSetLocal(_ key:String, Storage: String?)
    
    func syncGetLocalStorage(_ key: String) -> String?
    
    func syncRemoveLocalStorage(_ key:String)
    
}

@objc public class aSyncManager: NSObject, StorageProtocol {
    
    public static let share = aSyncManager()
    public static let storage_prefix = "MNHybrid_"
    
    override init(){ super.init() }
    
    public func syncSetLocal(_ key: String, Storage: String?) {
        
        UserDefaults.standard[aSyncManager.storage_prefix + key] = Storage
    }
    
    public func syncGetLocalStorage(_ key: String) -> String? {
        return UserDefaults.standard[aSyncManager.storage_prefix + key] as? String
    }
    
    public func syncRemoveLocalStorage(_ key: String) {
        
        UserDefaults.standard[aSyncManager.storage_prefix + key] = nil
        
    }
    
    deinit {
        print("\(self) deinit")
    }
}
